package com.shibida.shibidaProject.userInfo.dao;

import com.shibida.shibidaProject.userInfo.domain.OrderVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Repository
public interface OrderRepository extends JpaRepository<OrderVO, Integer> {
    @Query(value = "select t_order.*, t_user_base.user_name from t_order JOIN t_user_base ON t_order.user_id=t_user_base.id;",nativeQuery = true)
    List<OrderVO> queryAll();

    @Query(value = "select t_order.*, t_user_base.user_name from t_order JOIN t_user_base ON t_order.user_id=t_user_base.id WHERE t_order.id=:orderId ;", nativeQuery = true)
    OrderVO queryAllById(String orderId);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO `t_order` (`user_id`,`tar_user_id`,`order_number`,`order_time`,`food_id`) VALUES (:user_id,:tar_user_id,:order_number,:order_time,:food_id)", nativeQuery = true)
    void insertOrder(int user_id, int tar_user_id, String order_number, String order_time, String food_id);

    @Query(value = "SELECT LAST_INSERT_ID()", nativeQuery = true)
    int getLastInsertedId();
}
